#include "Game Engine/Header/Environment.h"
#include "Game Engine/Header/Camera.h"

Environment::Environment()
{
	mPosition	= D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
	mVelocity	= D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
}

Environment::~Environment()
{
}

D3DXVECTOR3& Environment::GetPosition()
{
	return mPosition;
}

D3DXVECTOR3& Environment::GetVelocity()
{
	mVelocity.y *= 0.6f;
	mVelocity.x *= 0.6f;
	mVelocity.z *= 0.6f;

	return mVelocity;
}

void Environment::SetPosition( D3DXVECTOR3 pos )
{
	mPosition = pos;

	mBody->translate( BTVector3( mPosition ) );
}

void Environment::SetVelocity( D3DXVECTOR3 vel )
{
	mVelocity = vel;
}

void Environment::Strafe( float d )
{
	D3DXVECTOR3 r = GetCamera().GetCameraRight();
	mVelocity += d * GetCamera().GetCameraRight();
}

void Environment::Walk( float d )
{
	mVelocity += d * GetCamera().GetCameraLook();
	//mVelocity.x += d * GetCamera().GetCameraLook().x;
	//mVelocity.z += d * GetCamera().GetCameraLook().z;
}

void Environment::Init( Mesh* mesh, Object::Shape shape, bool dynamic )
{
	Object::Init( mesh, shape, dynamic );

	mBody = Object::GetBody();
	mMesh = mesh;
}

void Environment::FixedPosition( D3DXVECTOR3& pos )
{
	Object::FixedPosition( pos );
}

void Environment::FixedRotation( float angle )
{
	Object::FixedRotation( angle );
}

void Environment::Draw( D3DXMATRIX& lightViewProj, D3DXMATRIX& mat )
{
	btMotionState* ms = mBody->getMotionState();
	if(ms == NULL)return;

	D3DXMATRIX T = BT2DX_MATRIX( *ms );

	mMesh->Draw( BT2DX_MATRIX( *ms ), lightViewProj );
}

D3DXMATRIX& Environment::World()
{
	return mWorld;
}